package com.nondo.dean.order.controller.api.inner;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.order.domain.OrderSubject;
import com.nondo.dean.order.service.OrderService;

import java.util.List;
import java.util.Map;

/**
 * 订单管理内部接口
 * @author zlj
 * @date 2018年5月12日
 */
@RestController("apiInnerOrder")
@RequestMapping("/{v}/inner/order")
public class OrderController {
    
    
    @Autowired
    OrderService orderService;
    
    /**
     * 查看订单详情
     *
     * @param request
     * @param response
     * @param id
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/info/{id}")
    public View<OrderSubject> info(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer id) {
        View<OrderSubject> view = new View<OrderSubject>(20000, "获取数据成功");

        OrderSubject order = null;
        if (id != null) {
            order = orderService.selectOrder(id);
        } else {
            order = new OrderSubject();
        }

        view.setData(order);
        return view;
    }

    /**
     * 更新app订单状态
     *
     * @param
     * @param
     * @param
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/update/app/order/status")
    public int updateAppOrderStatus(@RequestBody  View<Map<String,String>> view) {

        Map<String,String> map = view.getData();
        return  orderService.updateAppOrderStauts(map);

    }

    /**
     * 待发货订单列表
     *
     * @param request
     * @param response
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/sync/list")
    public View<List<OrderSubject>> getWaittingToDeliverOrderList(HttpServletRequest request, HttpServletResponse response) {
        View<List<OrderSubject>> view = new View<List<OrderSubject>>(20000, "获取数据成功");

        List<OrderSubject> orderList = orderService.getWaittingToDeliverOrderList();
        view.setData(orderList);
        
        return view;
    }

}